package fanshe2;

import java.lang.reflect.Field;

public class FanSheCar {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchFieldException {
        String classAllPath="fanshe2.Car";
        //获取反射类对象
        Class<?> cls = Class.forName(classAllPath);
        System.out.println("cls = " + cls);

        System.out.println("cls.getClass() = " + cls.getClass());

        System.out.println("cls.getPackage().getName() = " + cls.getPackage().getName());

        System.out.println("cls.getName() = " + cls.getName());

        //运行中创建对象实例
        Car car = (Car) cls.newInstance();
        System.out.println("car = " + car);

        Field brand = cls.getField("brand");
        System.out.println("brand.get(car) = " + brand.get(car));


    }
}
